package com.chis.spark;

import com.chis.jm.bean.jxc.trace.TraceBean;
import com.chis.jm.bean.jxc.trace.TraceCntStmBean;
import com.chis.jm.bean.jxc.trace.TraceMainBean;
import com.chis.jmdatakafka.service.IKafkaMsgService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wlj
 * @version 2019年05月05日
 * @Description   报废隔离生成追溯记录
 * @Company zwx
 */
public class TestYmzs {
    public static void main(String[] args) {

        //隔离单位
        Long unitCode = 3208032801L;
        //入库单号
        String incode = "BR32080328012019043001";
        //出库单号
        String outcode = "BC32080328012019043001";
        //出库时间
        Long outtime = 1556634600000L;
        //操作人
        Long man = 3208032801001L;
        //报废疫苗
        //仓库
        String storage = "5FC21E9C-5D87-AC62-2D96-BC58B4DAAE21";
        //库存
        String stmcnt = "683BDF99-A84B-1DB5-7A26-2BDBEFD0B2CA";
        //堆编号
        String heapcode = "BD32080328012019043001";
        //子表guid
        String subguid = "F77AE600-9BBD-DB7A-40F3-28E3C8EACE3C";
        //药品编码
        String bactcode = "86901960000096";
        //合并批号
        String batnmb = "201705031-2";
        //库存变化数量
        Integer stmcount = 294;
        //入库单价
        BigDecimal price = BigDecimal.ZERO;
        //生产日期
        Long produce = 1493870399000L;
        //有效期至
        Long ind = 1556855999000L;

        //业务主表bean
        TraceMainBean traceMainBean = new TraceMainBean();
        traceMainBean.setTableName("TD_DESTROYOUT_MAIN");//表名
        traceMainBean.setUnitCode(unitCode);//单位编码
        traceMainBean.setSupUnitCode(null);//供应商编码只发货使用
        traceMainBean.setMainCode(incode);//出入库单号
        traceMainBean.setSalCode(outcode);
        traceMainBean.setOptDate(outtime);//出入库时间
        traceMainBean.setOptCode(man);//操作人编码
        traceMainBean.setState(1);//状态
        traceMainBean.setSendType(1);//发货类型
        traceMainBean.setOptWay(1);//操作方式
        traceMainBean.setOptType(null);//操作来源

        //关联的库存数据bean
        List<TraceCntStmBean> traceCntStmBeans = new ArrayList<>();
        //报废疫苗
        TraceCntStmBean traceCntStmBean = new TraceCntStmBean();
        //查询操作库存量
        traceCntStmBean.setSrcStorageCode(storage);//目标仓库编码
        traceCntStmBean.setGuid(stmcnt);//库存guid通用
        traceCntStmBean.setSrcStmCnt(0); //当时仓库库存量 出库-未减库存 入库-未入库存
        traceCntStmBean.setDstguid(heapcode);//目标库存guid 转库使用
        traceCntStmBean.setSubid(subguid);//子表guid
        traceCntStmBean.setDstStorageCode(null);//目标仓库编码 转库使用
        traceCntStmBean.setMetaralCode(bactcode);//药品编码
        traceCntStmBean.setBatnmb(batnmb);//合并批号
        traceCntStmBean.setStmCnt(stmcount);//库存变化数量
        traceCntStmBean.setDstStmCnt(null);//目标仓库库存数 转库使用-未入库库存
        traceCntStmBean.setPurPrice(price);//入库单价
        traceCntStmBean.setProduceDate(produce);//生产日期
        traceCntStmBean.setIndDate(ind);//有效期至
        traceCntStmBeans.add(traceCntStmBean);
        //追溯消息封装
        TraceBean traceBean = new TraceBean();
        traceBean.setTraceMainBean(traceMainBean);
        traceBean.setTraceCntStmList(traceCntStmBeans);

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer_sparkdeal.xml" });
        IKafkaMsgService kafkaservice = (IKafkaMsgService) context.getBean("kafkaMsgService");
        kafkaservice.produceRedisMsg("TOPIC_TRACE",traceBean);


    }
}
